package com.ag.admin.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;

import com.ag.common.AjaxNotify;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;

public class PermissionAction extends BaseAction implements SessionAware {
	private static final long serialVersionUID = 5273325742528484494L;
	/**
	 * 调用权限服务逻辑组件
	 */
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	/**
	 * 提供Map<String, Object>类型的Session变量，用来保存Struts2注入的Session上下文
	 */
	private Map<String, Object> sessionMap;
	@Resource(name = "TransferPermissionServiceImpl")
	private com.ag.admin.service.IPermissionService iPermissionService;
	/**
	 * 异步请求返回
	 */
	private String ajaxRst;

	private String roleOgn, roleDst;

	public void setRoleDst(String roleDst) {
		this.roleDst = roleDst;
	}

	public void setRoleOgn(String roleOgn) {
		this.roleOgn = roleOgn;
	}

	public String getAjaxRst() {
		return ajaxRst;
	}

	/**
	 * 权限转移
	 * 
	 * @return
	 */
	public String transferPermission() {
		try {
			iPermissionService.transferPermission(roleOgn, roleDst, pms
					.getCurrentUser(sessionMap));
			ajaxRst = AjaxNotify.SUCCESS;
			return "operate";
		} catch (Exception e) {
			e.printStackTrace();
			ajaxRst = AjaxNotify.EXCEPTION;
			return "operate";
		}
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;
	}

}
